<template>
	<view class="nickname">
		<view class="input">
			<input type="text" v-model="name" :focus="focus" />
			<image src="../../../../static/del1.png" mode="" @click="del"></image>
		</view>
		<view class="button">
			<button type="warn" @click="addmanagement">保存</button>
		</view>
	</view>
</template>

<script>
	import {requestUrl} from '@/common/config.js'
	import md5 from '@/common/api/md5.js'
	export default {
		data() {
			return {
				name:'',
				focus:false,
				access_token:''
			};
		},
		methods:{
			addmanagement(){
				if(uni.getStorageSync('access_token')){
				this.access_token=JSON.parse(uni.getStorageSync('access_token'))
				}else{
					uni.showModal({
					    title: '提示',
					    content: '你还未登录，请先登录',
					    success: function (res) {
					        if (res.confirm) {
								uni.navigateTo({
									url:'/pages/login/login'
								})
					        } else if (res.cancel) {
					        }
					    }
					});
				}
				let time = Math.round(new Date().getTime() / 1000).toString()
				let _this = this
				let Time = ['time', time].join('=')
				let Access_token = ['access_token', this.access_token].join('=')
				let content = ['content=pinet.FeiMao.2017'].join()
				let arr = [content, Time].sort(function(a, b) {
					a - b
				})
				let newarr = md5(arr.join('&'))
				uni.request({
					url: requestUrl+'/app/user/changeNickname',
					method: "GET",
					data: {
						access_token: this.access_token,
						time: time,
						sign: newarr,
						nickname:this.name
					},
					success: function(res) {
						uni.showToast({
							title: res.data.message,
							icon:'none',
							duration:2000
						});
						if(res.data.errcode==0){
							uni.navigateBack({
								delta:1
							})
						}
					}
				});
			},
			del(){
				this.name=''
				this.focus=true
			}
		},
		onLoad: function (options) {
			this.name=options.name
		 }
	}
</script>

<style lang="less">
	.nickname{
		height: 100%;
		background-color: #F3F4F5;
		padding-top: 20rpx;
		.input{
			display: flex;
			padding: 30rpx 40rpx;
			background-color: #fff;
			justify-content: center;
			align-items: center;
			input{
				flex: 1;
			}
			image{
				width: 28rpx;
				height: 28rpx;
				padding: 10rpx 20rpx;	
			}
		}
		.button {
				width: 95%;
				margin: 0 auto;
				padding: 40rpx 0;
				button{
					border-radius: 20px;
					line-height: 80rpx;
				}
			}
	}
</style>
